package com.hqyj.springboot.modules.account.controller;

import com.github.pagehelper.PageInfo;

import com.hqyj.springboot.modules.account.entity.User;
import com.hqyj.springboot.modules.account.service.UserService;
import com.hqyj.springboot.modules.common.vo.Result;
import com.hqyj.springboot.modules.common.vo.Search;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping(value = "/login",consumes = "application/json")
    public Result<User> login(@RequestBody User user){
        return userService.login(user);
    }

    @PostMapping(value = "/user",consumes = "application/json")
    public Result<User> addUser(@RequestBody User user){
        return userService.addUser(user);

    }

    @PutMapping(value = "/user",consumes = "application/json")
    public Result<User> updateUser(@RequestBody User user){
        System.out.println("************"+user.getId());

        return userService.updateUser(user);
    }

    @GetMapping("/user/{id}")
    public User getUserById(@PathVariable int id){
        return userService.getUserById(id);
    }

    @DeleteMapping("/user/{id}")
    @RequiresPermissions("/api/user/{id}")
    public Result<Object> deleteUserById(@PathVariable int id){
        return userService.deleteUserById(id);
    }

    @PostMapping(value = "/users",consumes = "application/json")
    public PageInfo<User> getUsersBySearch(@RequestBody Search search){
        return userService.getUserBySearch(search);
    }









}
